class MusicController < ApplicationController
  def index
    @songs = Song.find(:all, :order => 'title ASC')
  end
  
  def albums
    @albums = Song.find(:all, :select => 'DISTINCT album', :order => 'album ASC').collect(&:album)
  end
  
  def album
    conditions = {:album => expand(params[:album])}
    params[:artist].nil? ? nil : conditions = {:artist => expand(params[:artist])}.merge(conditions)
    
    @songs = Song.find(:all, :conditions => conditions)
  end
  
  def artists
    @artists = Song.find(:all, :select => 'DISTINCT artist', :order => 'artist ASC').collect(&:artist)
  end
  
  def artist
    unless params[:all] == 'all'
      @albums = Song.find(:all, :conditions => ['artist = ?', expand(params[:id])]).collect(&:album).uniq
    else
      @songs = Song.find(:all, :conditions => ['artist = ?', expand(params[:id])])
    end  
  end

  def song
    @song = Song.find(params[:id])
  end
end
